package Model;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import POJO.ItemPOJO;

public class ItemModel {
	public static ArrayList<ItemPOJO> ChiTietDonHang(String id)
	{
	     Connection con = DataProvider.Connection();
	     ArrayList<ItemPOJO> listItem= new  ArrayList<ItemPOJO>();
	     if(con != null)
	     {
	    	  try {
	                PreparedStatement ps;
	                ps  = con.prepareCall("select * from [item] where order_id = ?");
	                ps.setString(1, id);
	                ResultSet rs = ps.executeQuery();
	                while( rs.next()) {
	                	ItemPOJO itPojo  = new ItemPOJO();
	                	itPojo.setId(rs.getInt("id"));
	                	itPojo.setOrder_id(rs.getInt("order_id"));
	                	itPojo.setProduct_id(rs.getInt("product_id"));
	                	itPojo.setPrice(rs.getFloat("price"));
	                	itPojo.setNumber(rs.getInt("number"));
	                	itPojo.setTotal(rs.getFloat("total"));
	                	
	                	listItem.add(itPojo);
	                }
	                con.close();
	            } catch (SQLException ex) {
	                return null;
	            }    
	     }
	     return listItem;
	}
}
